# @shuaige : 陈世玉
# @name :Spider.py
# @time :2024/12/5 20:50
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


def common_browser():
    chrome_options = Options()
    chrome_options.add_argument('--headless')

    # path是自己电脑的Chrome浏览器文件地址
    path = r'C:\Users\陈世玉\AppData\Local\Google\Chrome\Application\chrome.exe'
    chrome_options.binary_location = path

    browser = webdriver.Chrome(options=chrome_options)
    return browser
import time
# path='chromedriver.exe'
browser = common_browser()
url='https://bingli.iiyi.com/###'
browser.get(url)
#滑到底部
for i in range(20):
    js_bottom="window.scrollTo(0,document.body.scrollHeight)"
    browser.execute_script(js_bottom)
    print(f'爬取第{i+1}页数据')
    news=browser.find_elements_by_xpath('//div[@class="cont_desc"]')
    with open ('data1.txt','w',encoding='utf-8') as f:
        for n in news:
            f.write(n.text+'\n')
        # time.sleep(2)
# text=browser.page_source
    next=browser.find_element_by_link_text('查看更多')
    next.click()
# print(text)
browser.quit()
